package com.mz.ozy.adapter;

import android.graphics.Bitmap;
import android.view.ViewGroup;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions;
import com.bumptech.glide.request.target.SimpleTarget;
import com.bumptech.glide.request.transition.Transition;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.mz.ozy.R;

import java.util.List;


/**
 *
 */

public class ShopDetailAdapter extends BaseQuickAdapter<String, BaseViewHolder> {
//new GlideDrawableImageViewTarget(imageView) {
//        @Override
//        public void onResourceReady (GlideDrawable resource, GlideAnimation < ? super
//        GlideDrawable> animation){
//            super.onResourceReady(resource, animation);
//            if (null != resource) {
//                float width = resource.getIntrinsicWidth();
//                float height = resource.getIntrinsicHeight();
//                float ivWidth = imageView.getWidth();
//                if (ivWidth == 0) {
//                    ivWidth = imageView.getResources().getDisplayMetrics().widthPixels;
//                }
//                int ivHeight = (int) (height / width * ivWidth);
//                ViewGroup.LayoutParams lp = imageView.getLayoutParams();
//                lp.height = ivHeight;
//                imageView.setLayoutParams(lp);
//            }
//        }
//    }

    public ShopDetailAdapter(@Nullable List<String> data) {
        super(R.layout.item_shop_detail_pic, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, String item) {
        ImageView ivGoodsPic = helper.getView(R.id.iv_goods_pic);
//        Glide.with(mContext).load(item)
//                .transition(DrawableTransitionOptions.withCrossFade())//适用于Drawable
//                .into(ivGoodsPic);

        Glide.with(mContext).asBitmap().load(item).into(new SimpleTarget<Bitmap>() {
            @Override
            public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
                ivGoodsPic.setImageBitmap(resource);
            }
        });

 /*Glide.with(context).asBitmap().load(url).into(new BitmapImageViewTarget(imageView) {
     @Override
     public void onResourceReady (@NonNull Bitmap resource,
                                  @Nullable Transition<? super Bitmap> transition) {
         imageView.setImageBitmap(resource);
     }
 });*/
    }

}
